1
|
|
|
/* |
2
|
|
|
* Circles - Bring cloud-users closer together. |
3
|
|
|
* |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. See the COPYING file. |
6
|
|
|
* |
7
|
|
|
* @author Maxence Lange <[email protected]> |
8
|
|
|
* @copyright 2017 |
9
|
|
|
* @license GNU AGPL version 3 or any later version |
10
|
|
|
* |
11
|
|
|
* This program is free software: you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU Affero General Public License as |
13
|
|
|
* published by the Free Software Foundation, either version 3 of the |
14
|
|
|
* License, or (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
/** global: OC */ |
27
|
|
|
/** global: OCA */ |
28
|
|
|
/** global: Notyf */ |
29
|
|
|
|
30
|
|
|
/** global: nav */ |
31
|
|
|
/** global: elements */ |
32
|
|
|
/** global: curr */ |
33
|
|
|
/** global: api */ |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
var actions = { |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
joinCircleResult: function (result) { |
41
|
|
|
if (result.status === 0) { |
42
|
|
|
OCA.notification.onFail( |
43
|
|
|
"Cannot join this circle: " + |
44
|
|
|
((result.error) ? result.error : 'no error message')); |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
elements.removeMemberslistEntry(result.name); |
49
|
|
|
if (result.member.level == 1) { |
50
|
|
|
OCA.notification.onSuccess( |
51
|
|
|
"You have successfully joined this circle"); |
52
|
|
|
} else { |
53
|
|
|
OCA.notification.onSuccess( |
54
|
|
|
"You have requested an invitation to join this circle"); |
55
|
|
|
} |
56
|
|
|
actions.selectCircle(result.circle_id); |
57
|
|
|
}, |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
leaveCircleResult: function (result) { |
61
|
|
|
if (result.status == 1) { |
62
|
|
|
|
63
|
|
|
elements.mainUIMembers.children("[member-id='" + result.name + "']").each( |
64
|
|
|
function () { |
65
|
|
|
$(this).hide(300); |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
actions.selectCircle(result.circle_id); |
69
|
|
|
OCA.notification.onSuccess( |
70
|
|
|
"You have successfully left this circle"); |
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
OCA.notification.onFail( |
75
|
|
|
"Cannot leave this circle: " + |
76
|
|
|
((result.error) ? result.error : 'no error message')); |
77
|
|
|
|
78
|
|
|
}, |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
|
82
|
|
|
|
83
|
|
|
createCircleResult: function (result) { |
84
|
|
|
var str = actions.getStringTypeFromType(result.type); |
85
|
|
|
|
86
|
|
|
if (result.status == 1) { |
87
|
|
|
OCA.notification.onSuccess(str + " '" + result.name + "' created"); |
88
|
|
|
nav.displayCirclesList(result.circle.type); |
89
|
|
|
actions.selectCircle(result.circle.id); |
90
|
|
|
return; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
OCA.notification.onFail( |
94
|
|
|
str + " '" + result.name + "' NOT created: " + |
95
|
|
|
((result.error) ? result.error : 'no error message')); |
96
|
|
|
}, |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
selectCircleResult: function (result) { |
100
|
|
|
|
101
|
|
|
elements.mainUIMembers.emptyTable(); |
102
|
|
|
if (result.status < 1) { |
103
|
|
|
OCA.notification.onFail( |
104
|
|
|
'Issue while retreiving the details of a circle: ' + |
105
|
|
|
((result.error) ? result.error : 'no error message')); |
106
|
|
|
return; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
elements.navigation.children('.circle').removeClass('selected'); |
110
|
|
|
elements.navigation.children(".circle[circle-id='" + result.circle_id + "']").each( |
111
|
|
|
function () { |
112
|
|
|
$(this).addClass('selected'); |
113
|
|
|
}); |
114
|
|
|
|
115
|
|
|
elements.emptyContent.hide(800); |
116
|
|
|
elements.mainUI.fadeIn(800); |
117
|
|
|
curr.circle = result.circle_id; |
118
|
|
|
curr.circleLevel = result.details.user.level; |
119
|
|
|
|
120
|
|
|
nav.displayCircleDetails(result.details); |
121
|
|
|
nav.displayMembersInteraction(result.details); |
122
|
|
|
nav.displayMembers(result.details.members); |
123
|
|
|
}, |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
listCirclesResult: function (result) { |
127
|
|
|
|
128
|
|
|
if (result.status < 1) { |
129
|
|
|
OCA.notification.onFail( |
130
|
|
|
'Issue while retreiving the list of the Circles: ' + |
131
|
|
|
((result.error) ? result.error : 'no error message')); |
132
|
|
|
return; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
elements.resetCirclesList(); |
136
|
|
|
|
137
|
|
|
var data = result.data; |
138
|
|
|
for (var i = 0; i < data.length; i++) { |
139
|
|
|
var tmpl = elements.generateTmplCircle(data[i]); |
140
|
|
|
elements.navigation.append( |
141
|
|
|
'<div class="circle" circle-id="' + data[i].id + '">' + tmpl + '</div>'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
elements.navigation.children('.circle').on('click', function () { |
145
|
|
|
actions.selectCircle($(this).attr('circle-id')); |
146
|
|
|
}); |
147
|
|
|
}, |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
selectCircle: function (circle_id) { |
151
|
|
|
curr.searchUser = ''; |
152
|
|
|
elements.addMember.val(''); |
153
|
|
|
|
154
|
|
|
api.detailsCircle(circle_id, actions.selectCircleResult); |
155
|
|
|
}, |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* |
160
|
|
|
* @param search |
161
|
|
|
*/ |
162
|
|
|
searchMembersRequest: function (search) { |
163
|
|
|
|
164
|
|
|
if (curr.searchUser == search) { |
165
|
|
|
return; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
curr.searchUser = search; |
169
|
|
|
|
170
|
|
|
$.get(OC.linkToOCS('apps/files_sharing/api/v1', 1) + 'sharees', |
171
|
|
|
{ |
172
|
|
|
format: 'json', |
173
|
|
|
search: search, |
174
|
|
|
perPage: 200, |
175
|
|
|
itemType: 'principals' |
176
|
|
|
}, actions.searchMembersResult); |
177
|
|
|
}, |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
searchMembersResult: function (response) { |
181
|
|
|
|
182
|
|
|
elements.membersSearchResult.children().remove(); |
183
|
|
|
|
184
|
|
|
if (response === null || |
185
|
|
|
(response.ocs.data.users.length === 0 && response.ocs.data.exact.users.length === 0)) { |
186
|
|
|
elements.membersSearchResult.fadeOut(0); |
187
|
|
|
return; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
elements.fillMembersSearch(response.ocs.data.exact.users, response.ocs.data.users); |
191
|
|
|
|
192
|
|
|
$('.members_search').on('click', function () { |
193
|
|
|
api.addMember(curr.circle, $(this).attr('searchresult'), |
194
|
|
|
actions.addMemberResult); |
195
|
|
|
}); |
196
|
|
|
elements.membersSearchResult.fadeIn(300); |
197
|
|
|
}, |
198
|
|
|
|
199
|
|
|
|
200
|
|
|
addMemberResult: function (result) { |
201
|
|
|
|
202
|
|
|
if (result.status == 1) { |
203
|
|
|
OCA.notification.onSuccess( |
204
|
|
|
"Member '" + result.name + "' successfully added to the circle"); |
205
|
|
|
|
206
|
|
|
nav.displayMembers(result.members); |
207
|
|
|
return; |
208
|
|
|
} |
209
|
|
|
OCA.notification.onFail( |
210
|
|
|
"Member '" + result.name + "' NOT added to the circle: " + |
211
|
|
|
((result.error) ? result.error : 'no error message')); |
212
|
|
|
}, |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
getStringTypeFromType: function (type) { |
216
|
|
|
switch (type) { |
|
|
|
|
217
|
|
|
case '1': |
218
|
|
|
return 'Personal circle'; |
219
|
|
|
case '2': |
220
|
|
|
return 'Hidden circle'; |
221
|
|
|
case '4': |
222
|
|
|
return 'Private circle'; |
223
|
|
|
case '8': |
224
|
|
|
return 'Public circle'; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
return 'Circle'; |
228
|
|
|
}, |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
removeMemberResult: function (result) { |
232
|
|
|
if (result.status == 1) { |
233
|
|
|
|
234
|
|
|
elements.rightPanel.fadeOut(300); |
235
|
|
|
elements.mainUIMembers.children("[member-id='" + result.name + "']").each( |
236
|
|
|
function () { |
237
|
|
|
$(this).hide(300); |
238
|
|
|
}); |
239
|
|
|
OCA.notification.onSuccess( |
240
|
|
|
"Member '" + result.name + "' successfully removed from the circle"); |
241
|
|
|
return; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
OCA.notification.onFail( |
245
|
|
|
"Member '" + result.name + "' NOT removed from the circle: " + |
246
|
|
|
((result.error) ? result.error : 'no error message')); |
247
|
|
|
}, |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* |
252
|
|
|
*/ |
253
|
|
|
onEventNewCircle: function () { |
254
|
|
|
curr.circle = 0; |
255
|
|
|
curr.circleLevel = 0; |
256
|
|
|
|
257
|
|
|
elements.navigation.hide('slide', 800); |
258
|
|
|
elements.circlesList.children('div').removeClass('selected'); |
259
|
|
|
elements.emptyContent.show(800); |
260
|
|
|
elements.mainUI.fadeOut(800); |
261
|
|
|
}, |
262
|
|
|
|
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* |
266
|
|
|
*/ |
267
|
|
|
onEventNewCircleName: function () { |
268
|
|
|
this.onEventNewCircle(); |
269
|
|
|
nav.displayOptionsNewCircle((elements.newName.val() !== '')); |
270
|
|
|
}, |
271
|
|
|
|
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* |
275
|
|
|
*/ |
276
|
|
|
onEventNewCircleType: function () { |
277
|
|
|
this.onEventNewCircle(); |
278
|
|
|
elements.newTypeDefinition.children('div').fadeOut(300); |
279
|
|
|
$('#circles_new_type_' + elements.newType.children('option:selected').val()).fadeIn( |
280
|
|
|
300); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
}; |
285
|
|
|
|